package com.evil.file.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.evil.common.core.enums.RCodeEnum;
import com.evil.common.core.exception.BusinessException;
import com.evil.file.pojo.entity.File;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

/**
 * 文件表
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
public interface FileMapper extends BaseMapper<File> {

    Optional<File> isExistById(@Param("id") Long id);

    default File findById(Long id) {
        return this.isExistById(id).orElseThrow(() -> new BusinessException(RCodeEnum.ERROR_FILE_NOT_FOUND));
    }

    Optional<File> isExistByCode(@Param("code") String code);

    default File findByCode(String code) {
        return this.isExistByCode(code).orElseThrow(() -> new BusinessException(RCodeEnum.ERROR_FILE_NOT_FOUND));
    }

    List<File> findByIds(@Param("ids") Collection<Long> ids, @Param("filterDeleted") boolean filterDeleted);

    List<File> findByCodes(@Param("codes") Collection<String> codes, @Param("filterDeleted") boolean filterDeleted);
}